<template>
  <el-dialog :append-to-body="true" :visible.sync="dialog" title="修改商品销量" width="600px">
    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="120px">
      <el-form-item label="销量:" prop="dealTimes">
        <el-input v-model.number="form.dealTimes" style="width: 370px;"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button type="primary" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { setDealTimes } from '@/api/mall/commodity'
export default {
  components: { },
  data() {
    return {
      dialog: false,
      form: {
        dealTimes: '',
        ids: []
      },
      rules: {
        dealTimes: [
          { required: true, message: '请输入数字', trigger: 'blur', type: 'number' }
        ]
      }
    }
  },
  methods: {
    cancel() {
      this.resetForm()
    },
    doSubmit() {
      // 表单验证
      this.$refs['form'].validate((valid) => {
        // 通过
        if (valid) {
          setDealTimes(this.form).then(res => {
            if (res) {
              // 执行成功
              this.resetForm()
              this.$notify({
                title: '修改成功',
                type: 'success',
                duration: 2500
              })
              this.$parent.init()
            } else {
              // 系统不会报错，但是会有提示语，告知如何操作
              this.$notify({
                title: res,
                type: 'error',
                duration: 2500
              })
            }
          }).catch(err => {
            console.log(err.response.data.message)
          })
        }
      })
    },
    resetForm() {
      this.dialog = false
      this.$refs['form'].resetFields()
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  /deep/ .el-input-number .el-input__inner {
    text-align: left;
  }

</style>
